﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeKicker.BBCode;

namespace LastoRevival.ForumCode
{
	public class BBCodeParserExtension
	{
		private BBCodeParser parser;

		public BBCodeParserExtension(IList<BBTag> tags)
		{
			parser = new BBCodeParser(tags);
		}

		public string ToHtml(string bbCode)
		{
			// don't blow up on nulls
			if (string.IsNullOrEmpty(bbCode))
			{
				return string.Empty;
			}

			// replace linebreaks as well
			// to make sure we're cross-platform, strip out, we'll convert to linefeeds before replacing
			var html = parser.ToHtml(bbCode);

			// convert crlf to lf
			html = html.Replace("\r\n", "\n");
			// convert cf to lf
			html = html.Replace("\r", "\n");

			// now we should only be left with lf
			html = html.Replace("\n", "<br />");

			return html;
		}

	}
}
